package com.tanhua.server.controller;

/**
 * @ClassName PeachblossomController
 * @Description TODO
 * @Author zxs
 * @Date 2021/4/20 10:28
 * Version 1.0
 */

import com.tanhua.commons.exception.TanHuaException;
import com.tanhua.domain.vo.PeachBlossomVo;
import com.tanhua.domain.vo.PublishVo;
import com.tanhua.server.service.PeachblossomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 桃花传音-控制层
 */
@RestController
@RequestMapping("/peachblossom")
public class PeachblossomController {

    @Autowired
    private PeachblossomService peachblossomService;

    //桃花传音-发送语音
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity peachblossomVoice( MultipartFile soundFile){

        peachblossomService.voices(soundFile);
        return ResponseEntity.ok(null);
    }

    //桃花传音-接收语音（学生实战）
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity getPeachblossomVoice(){
        PeachBlossomVo peachBlossomVo  = peachblossomService.findVoice();
        if (peachBlossomVo == null) {
            throw new TanHuaException("今日次数已经用完");
        }
        return ResponseEntity.ok(peachBlossomVo);
    }


}
